
const { cookie } = require('request');
var request = require('request');

let url = "http://wljy.whut.edu.cn/edu/eduStuCourse/saveCourseLearnTime.ajax" ;
var requestData="userid=212113412100006&courlibNo=1963&learnTime=";
 

for (let i = 0; i < 10; i++) {
    let r = random2(25,30)
    console.log("r :", r);
}

const sleep = function (ms){
    return new Promise(resolve => setTimeout(resolve, ms))
}
const send = async function(){

    for(let i=0;i<600 *2;i++){
      let time = random(500,1500)
      let learnTime = random2(25,30)
      console.log('send:%s， time:%s, learnTime:%s', i,time,learnTime)
      httprequest2(url,requestData+learnTime)
      await sleep(time)
    // console.log();
    }
  }
  
send()

function random(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

function random2(min,max){
    let n = Math.random()*(max-min+1)+min;
    if(n>30){
        return 30 ;
    }
    return n;
}



function httprequest2(url, data){
    let cookie = "xxxx"
    // console.log("url :", url) // 请求成功的处理逻辑
    request({
        url: url,
        method: "POST",
        json: false,
        headers: {
            "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            Cookie: cookie, //这里是登陆后得到的cookie,(重点)
        },
        body: data
    }, function(error, response, body) {
        try {
            console.log("body:", body) 
        }catch(e) {
        }

    });
};





 
 